Send click, conversion, and view events to the Algolia Insights API with Google Tag Manager.
queryID
when sending search-related events to the Insights API, such as with the clickedObjectIDsAfterSearch
method.
To include the queryID
in the search response, set clickAnalytics
to true
.
To identify users, add the userToken
parameter.
data-insights-index
. Select a parent DOM element that contains both your filters and hits UI elements to capture events related to both.data-insights-object-id
. The unique object identifier for the Algolia hit.data-insights-position
. The position in the search results, starting with 1 and taking paginated search results into account.data-insights-query-id
. A unique identifier for relating the search query and event.data-insights-filter
attribute to each filter element (format: ${attribute}:${value}
):
search-insights
library,
use its onUserTokenChange
method to sync the user token with GTM:
onUserTokenChange
method is supported in search-insights
versions 1.5.0 or later.
Sign into GTM
Select the Algolia template
Add template to GTM workspace
Verify addition
Configure variables
Select the click element
User-defined variables
Select data layer
Add Algolia Insights user token
Algolia Insights User Token
as the variable name and algoliaUserToken
as the data layer variable name.User-defined variables
Select custom JavaScript
Add JavaScript code
Algolia Get Data Attributes
as variable name and add the following JavaScript code:User-defined variables
Add variable and JavaScript code
Algolia Insights Index
as variable name and add the following JavaScript code:data-insights-index
attribute.For example, if you have the following HTML:div
element with the id index-1
for tracking events:User-defined variables
Add variable and JavaScript
Algolia Insights ObjectIDs
as variable name and add the following JavaScript code:User-defined variables
Add variable and JavaScript
Algolia Insights Positions
as variable name and add the following JavaScript code:User-defined variables
Add variable and JavaScript
Algolia Insights QueryID
as the variable name and add the following JavaScript code:User-defined variables
Add variable and JavaScript
Algolia Insights Viewed Filters
as the variable name and add the following JavaScript code:User-defined variables
Add variable and JavaScript
Algolia Insights Clicked Filters
as variable name and add the following JavaScript code:Hits Viewed
Custom Event
Hits Viewed
Click - All Elements
as the trigger type
and configure the trigger to fire only when the click text matches View Details.
.ais-RefinementList-labelText
.
You must add the data-insights-filter
attribute to the element matching the .ais-RefinementList-labelText
selector,
or to a parent element at a higher level in the DOM.
Algolia Search Insights tag
Enter credentials
Add trigger
viewedObjectIDs
method.
Hits Viewed
Algolia Search Insights
Viewed Object IDs
viewedFilters
method.
Attributes:
Hits Viewed
Algolia Search Insights
Viewed Filters
{{Algolia Insights Viewed Filters}}
clickedObjectIDsAfterSearch
method.
View Details
Algolia Search Insights
Clicked Object IDs After Search
clickedObjectIDs
method.
Attributes:
View Details
Algolia Search Insights
Clicked Object IDs
{{Algolia Insights Clicked Filters}}
attribute and corresponds to the clickedFilters
method.
Attributes:
View Details
Algolia Search Insights
Clicked Filters
convertedObjectIDsAfterSearch
method. Set up this tag like the related click tag.convertedObjectIDs
method. Set up this tag like the related click tag.convertedFilters
method. Set up this tag like the related click tag.["product-1", "product-2"]
, then your object data list might look like: